package main

import (
	"flag"
	"net/http"

	"gitee.com/dxyinme/raft/rlib"
	"github.com/golang/glog"
)

var (
	NodeName    = flag.String("nodeName", "", "nodeName of this server")
	ClusterFile = flag.String("clusterFile", "conf/cluster.json", "Cluster config file of this server")
)

func main() {
	flag.Parse()
	err := rlib.LoadClusterConfig(*ClusterFile)
	rlib.ClusterConfigSingleton.SetNodeName(*NodeName)
	if err != nil {
		glog.Fatal(err)
	}
	raftServer := &rlib.RaftServer{}
	raftServer.Init()
	rlib.InitRaftServerHttpApi(raftServer)
	addr := rlib.ClusterConfigSingleton.GetAddrByNodeName(*NodeName)
	glog.Infof("begin to serve in addr %s", addr)
	if err = http.ListenAndServe(addr, nil); err != nil {
		glog.Fatal(err)
	}
}
